package com.ssy.mall.common;

import com.google.common.collect.Sets;
import com.ssy.mall.exception.SsyMallException;
import com.ssy.mall.exception.SsyMallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class Constant {
    public static final String SALT = "8s4hfkdejkkfmk;,./[-=]'/da1hjnvmka2u8nkj3";
    public static final String SSY_MALL_USER = "ssy_mall_user";
    @Value("${file.upload.dir")
    public static String FILE_UPLOAD_DIR;
    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir){
        FILE_UPLOAD_DIR = fileUploadDir;
    }
    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc","price asc");
    }
    public interface SaleStatus{
        int NOT_SALE = 0;//商品下架状态
        int SALE = 1; //商品上架状态
    }
    public interface CartSelected{
        int UN_CHECKED= 0;//购物车未选中状态
        int CHECKED = 1; //购物车选中状态
    }
    public enum OrderStatusEnum{
        CANCELED(0,"用户已取消"),
        NOT_PAID(10,"未付款"),
        PAID(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易完成");

        private int code;
        private String value;


        OrderStatusEnum(int code,String value) {
            this.value = value;
            this.code = code;
        }
        public static OrderStatusEnum codeof(int code){
            for (OrderStatusEnum orderStatusEnum:values()){
                if (orderStatusEnum.getCode() == code){
                    return orderStatusEnum;
                }
            }
            throw new SsyMallException(SsyMallExceptionEnum.NO_ENUM);
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }
}
